home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / mntlib25.zoo / access.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  876b  |  45 lines

  1. /* access() emulation; relies heavily on stat() */
  2.  
  3. #include <types.h>
  4. #include <stat.h>
  5. #include <fcntl.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8.  
  9. extern int __mint;
  10.  
  11. int
  12. access(path, mode)
  13.     const char *path;
  14.     int mode;
  15. {
  16.     struct stat sb;
  17.  
  18.     if (stat(path, &sb) < 0)
  19.         return -1;    /* errno was set by stat() */
  20.     if (mode == F_OK)
  21.         return 0;    /* existence test succeeded */
  22.  
  23. /* somewhat crufty code -- relies on R_OK, etc. matching the bits in the
  24.    file mode, but what the heck, we can do this
  25.  */
  26.     if (__mint < 9 || ( geteuid() == sb.st_uid ) ) {
  27.         if ( ((sb.st_mode >> 6) & mode) == mode )
  28.             return 0;
  29.         else
  30.             goto accdn;
  31.     }
  32.  
  33.     if ( getegid() == sb.st_gid ) {
  34.         if ( ((sb.st_mode >> 3) & mode) == mode )
  35.             return 0;
  36.         else
  37.             goto accdn;
  38.     }
  39.  
  40.     if ( (sb.st_mode & mode) == mode)
  41.         return 0;
  42. accdn:
  43.     errno = EACCESS; return -1;
  44. }
  45.